package com.example.demo.controller;

import com.example.demo.entity.Banner;
import com.example.demo.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;

import com.example.demo.controller.vo.BannerRequest;
import com.example.demo.controller.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/banners")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @PostMapping("/goods/{id}")
    public ResponseResult<List<Banner>> addBanners(@PathVariable("id") Integer goodsId, @RequestBody BannerRequest request) {
        List<Banner> result = bannerService.addBanners(goodsId, request.getBanners());
        return ResponseResult.success(result);
    }

    @GetMapping("/goods/{id}")
    public ResponseResult<List<Banner>> getBannersByGoodsId(@PathVariable("id") Integer goodsId) {
        List<Banner> banners = bannerService.getBannersByGoodsId(goodsId);
        return ResponseResult.success(banners);
    }

    @PostMapping("/delete/{id}")
    public ResponseResult<Boolean> deleteBannerById(@PathVariable("id") Integer id) {
        boolean result = bannerService.deleteBannerById(id);
        return ResponseResult.success(result);
    }
}